package course_hashMap;

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
public class MyHashMap {
    public static void main(String[] args) {
        Map<String,people> PeopleHashMap =new HashMap<>();
        Map<String,animal> animalHashMap =new HashMap<>();
        people liubei=new people();
        people guanyu=new people();
        people zhangfei=new people();
        people huamulan=new people();
        people sulie=new people();
        people bailishouyue=new people();
        animal daji=new animal();
        animal mengqi=new animal();
        animal peiqinghu=new animal();

        liubei.setAll("刘备",35,"射手");
        PeopleHashMap.put(liubei.getName(),liubei);

        zhangfei.setAll("张飞",33,"辅助");
        PeopleHashMap.put(zhangfei.getName(),zhangfei);

        guanyu.setAll("关羽",34,"战士");
        PeopleHashMap.put(guanyu.getName(),guanyu);

        sulie.setAll("苏烈",45,"肉盾");
        PeopleHashMap.put(sulie.getName(),sulie);

        huamulan.setAll("花木兰",23,"战士");
        PeopleHashMap.put(huamulan.getName(),huamulan);

        bailishouyue.setAll("百里守约",19,"射手");
        PeopleHashMap.put(bailishouyue.getName(),bailishouyue);

        daji.setAll("妲己",18,"法师");
        animalHashMap.put(daji.getName(),daji);

        mengqi.setAll("梦奇",12,"肉法师");
        animalHashMap.put(mengqi.getName(),mengqi);

        peiqinghu.setAll("裴擒虎",26,"射手");
        animalHashMap.put(peiqinghu.getName(),peiqinghu);

        //第一种遍历方法
        System.out.println("\n人物类英雄：\n");
        Iterator iter =PeopleHashMap.entrySet().iterator();
        while(iter.hasNext()){
            Map.Entry name = (Map.Entry)iter.next();
            String nameKey = (String)name.getKey();
            System.out.print("\t"+nameKey+"\t 的职业：\t"+PeopleHashMap.get(nameKey).getPostion());
            System.out.println("\t 年龄 \t"+PeopleHashMap.get(nameKey).getAge());
        }
        //第二种遍历方法
        System.out.println("\n动物类英雄：\n");
        animalHashMap.forEach((key,value)->{
            System.out.print("\t"+key+"\t 的职业：\t"+value.getPostion());
            System.out.println("\t 年龄 ：\t"+value.getAge());
        });
    }
}
